# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function

from ..ops import IdxMax, IdxMin
from ..base import OpsFeature

from .close import Close

class AROONU(OpsFeature):
    """Technical Indicator - AROON (Up)

    - AROONU = IDXMAX(CLOSE, N) / N
    """
    def __init__(self, feature=None, N=25):
        self.feature = feature or Close()
        self.N = N

    def __str__(self):
        name = type(self).__name__.lower()
        if str(self.feature) != 'close':
            name += '_'+str(self.feature)
        if self.N != 25:
            name += '_'+str(self.N)
        return name
    
    def _load_internal(self, instrument, start_time, end_time, freq):
        aroonu = IdxMax(self.feature, self.N) / self.N * 100
        return aroonu.load(instrument, start_time, end_time, freq)

class AROOND(OpsFeature):
    """Technical Indicator - AROON (Down)

    - AROOND = IDXMIN(CLOSE, N) / N
    """
    def __init__(self, feature=None, N=25):
        self.feature = feature or Close()
        self.N = N

    def __str__(self):
        name = type(self).__name__.lower()
        if str(self.feature) != 'close':
            name += '_'+str(self.feature)
        if self.N != 25:
            name += '_'+str(self.N)
        return name
    
    def _load_internal(self, instrument, start_time, end_time, freq):
        aroond = IdxMin(self.feature, self.N) / self.N * 100
        return aroond.load(instrument, start_time, end_time, freq)
    
class AROON(OpsFeature):
    """Technical Indicator - AROON (Oscillator)

    - AROON = AROONU - AROOND
    """
    def __init__(self, feature=None, N=25):
        self.feature = feature or Close()
        self.N = N

    def __str__(self):
        name = type(self).__name__.lower()
        if str(self.feature) != 'close':
            name += '_'+str(self.feature)
        if self.N != 25:
            name += '_'+str(self.N)
        return name
    
    def _load_internal(self, instrument, start_time, end_time, freq):
        aroon = AROONU() - AROOND()
        return aroon.load(instrument, start_time, end_time, freq)
